﻿using System;
using System.Drawing;

namespace PlantsZombies.Common.Bullet
{
    [PlantZombie(SpeciesType.Sunflower)]
    public unsafe class SunflowerBullet : BulletObject
    {
        public SunflowerBullet(ImageObject[] images, GameObject gameObject)
            : base(new Size(50, 50), images, gameObject)
        {

        }
        DateTime lastDate = DateTime.MinValue;
        public override void Attack(ListGameObject* ptr)
        {
            if (lastDate == DateTime.MinValue)
            {
                lastDate = DateTime.Now;
            }
            else
            {
                if ((DateTime.Now - lastDate).TotalSeconds >= 8)
                {
                    _bullets.Add(new BulletPoint
                    {
                        Index = 0,
                        X = _gameObject.Location.X + 20,
                        Y = _gameObject.Location.Y,
                    });
                    lastDate = DateTime.Now;
                }
            }
            if (_bullets.Count > 3)
                _bullets.RemoveAt(0);
        }
        public override void Move(ListGameObject* ptr)
        {
            if (_imagesBullet != null)
            {
                int maxHeight = _gameObject.MaxRow * _gameObject.CellHeight + _gameObject.StartY;
                foreach (var image in _bullets)
                {
                    image.Y += 5;
                    if (image.Y + BulletSize.Height > maxHeight)
                        image.Y = maxHeight - BulletSize.Height / 2;
                }
            }
        }
    }
}
